package com.warthur.spring.shiro.framework.handler;

import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author warthur
 * @date 2018/09/09
 */
@RestControllerAdvice
public class ExceptionCatchHandler {

    @ExceptionHandler(value = {AuthorizationException.class})
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    public String unauthorizedError() {
        return "{\"status\":401,\"success\":false,\"message\":\"未授权访问！\"}";
    }
}
